package com.mkh.st.admin.feign;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.mkh.st.admin.api.entity.SysArea;
import com.mkh.st.admin.api.feign.IParamProvider;
import com.mkh.st.admin.service.StSnService;
import com.mkh.st.admin.service.SysAreaService;
import com.mkh.st.admin.service.SysPublicParamService;
import com.mkh.st.common.core.util.R;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AllArgsConstructor
public class ParamProvider implements IParamProvider {

	private final SysPublicParamService sysPublicParamService;

	private final StSnService stSnService;

	private final SysAreaService areaService;

	@Override
	@GetMapping("/param/provider/publicValue/{key}")
	public R<String> getByKey(@PathVariable("key") String key) {
		return R.ok(sysPublicParamService.getSysPublicParamKeyToValue(key));
	}

	@Override
	@GetMapping("/param/provider/getSequenceCode")
	public R<String> getSequenceCode(@RequestParam("code") String code) {
		return R.ok(stSnService.getSequenceCode(code));
	}

	@Override
	public R<SysArea> getSysArea(Long cityCode) {
		return R.ok(areaService.getOne(Wrappers.<SysArea>lambdaQuery().eq(SysArea::getAreaCode,cityCode)));
	}
}
